import threading

class Monkey(threading.Thread):
    dialogues = ["呆子", "你个憨货","吃我一棍,呆子"]
    def __init__(self,cond : threading.Condition):
        self.cond = cond
        super().__init__(name="孙悟空")

    def run(self) -> None:
        with self.cond:
            while len(self.dialogues) > 0:
                self.cond.wait()
                print(f"{self.name} : {self.dialogues.pop(0)}")
                self.cond.notify()



class Pig(threading.Thread):
    dialogues =["猴哥","师傅被妖怪抓走了","我们分行李回老家吧"]
    def __init__(self,cond : threading.Condition):
        self.cond = cond
        super().__init__(name="猪八戒")

    def run(self) -> None:
        with self.cond:
            while len(self.dialogues) > 0:
                print(f"{self.name} : {self.dialogues.pop(0)}" )
                self.cond.notify()
                self.cond.wait()


if __name__ == '__main__':
    cond = threading.Condition()
    monkey = Monkey(cond)
    pig = Pig(cond)
    monkey.start()
    pig.start()
